package com.intelligentmeterreadingsys.waterlist.querywaterlist.activity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.intelligentmeterreadingsys.R;
import com.intelligentmeterreadingsys.waterlist.db.WaterListDaoImpl;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

/**
 * 设置查询用户条件
 * @author king
 *
 */
public class SetQueryConditionActivity extends Activity{
	
	public Button button1;
	
	public EditText edit1;//用户编号
	
	public EditText edit2;//用水性质
	
	public String bandingstatus="3";
	public EditText edit4;//水表地址
	
	public Spinner edit5;//表册
	
    public Spinner spinner;//抄表状态
    
    public Spinner spinner1;//绑定状态
		
    private String waterlistid;//表册ID
	
	public Map<String, String> map=null;
	
	public String[] date={"全部"};
	
	public String getWaterlistid() {
		return waterlistid;
	}

	public void setWaterlistid(String waterlistid) {
		this.waterlistid = waterlistid;
	}

	private String usertype;
	
	
	public String getUsertype() {
		return usertype;
	}

	public void setUsertype(String usertype) {
		this.usertype = usertype;
	}

	public QueryWaterListActivity act;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	
		super.onCreate(savedInstanceState);
		 act=(QueryWaterListActivity)getParent();
		setContentView(R.layout.waterlist_query_condition);	
		inti();		
	}
	
	public void inti(){
		edit1=(EditText)findViewById(R.id.condition_username);
		edit2=(EditText)findViewById(R.id.condition_usernumber);
		edit4=(EditText)findViewById(R.id.condition_waterproperties);
		edit5=(Spinner)findViewById(R.id.condition_wateradds);
		spinner=(Spinner)findViewById(R.id.condition_copystatus);
		spinner1=(Spinner)findViewById(R.id.condition_isbandingstatus);
		 button1=(Button)findViewById(R.id.condition_query_button);
		 WaterListDaoImpl dao=new WaterListDaoImpl(this);
		map= dao.queryWaterList();
		dao.close();
		
		List<String> listss=new ArrayList<String>();
		listss.add("全部");
		for(String s:map.keySet()){
			listss.add(s);
		}
		spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if(arg0.getItemAtPosition(arg2).toString().equals("未绑定")){
					bandingstatus="2";
				}else if(arg0.getItemAtPosition(arg2).toString().equals("已绑定")){
					bandingstatus="3";
				}
				
				
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				bandingstatus="3";
				
			}
		});
		 spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

				@Override
				public void onItemSelected(AdapterView<?> arg0, View arg1,
						int arg2, long arg3) {
					usertype=arg0.getItemAtPosition(arg2).toString();
					
				}

				@Override
				public void onNothingSelected(AdapterView<?> arg0) {
					usertype="未抄";
					
				}
				 
			});
			
		 button1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				QueryWaterListActivity act=(QueryWaterListActivity)getParent();
				//act.setUsername(edit1.getEditableText().toString());
				act.setUsernumber(edit2.getEditableText().toString());
				
				act.setWaterproperties(edit4.getEditableText().toString());
				act.setCopystatus(usertype);
				
				
			}
		});
		 
		 ArrayAdapter<String> ada1=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,listss);//放数据
		 ada1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);//设置打开方式
	       edit5.setAdapter(ada1);
	       edit5.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				
				if(arg0.getItemAtPosition(arg2).toString().equals("全部")){
					waterlistid="0";
				}else{
					waterlistid=map.get(arg0.getItemAtPosition(arg2).toString());
				}
				
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				waterlistid="0";
				
			}
		});
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}
	
	

}
